package app.auto.runner.base;

import android.app.Activity;
import android.app.LocalActivityManager;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;

import app.auto.AndroidInstance;

import static android.view.ViewGroup.FOCUS_AFTER_DESCENDANTS;

public class ActivityUtil extends AndroidInstance {

    public LocalActivityManager mLocalActivityManager;

    public LocalActivityManager getmLocalActivityManager() {
        return mLocalActivityManager;
    }

    public View activityToView(LocalActivityManager mLocalActivityManager, Context parent,String id, Intent intent) {
        final Window w = mLocalActivityManager.startActivity(id, intent);
        final View view = w != null ? w.getDecorView() : null;
        if (view != null) {
            view.setVisibility(View.VISIBLE);
            view.setFocusableInTouchMode(true);
            ((ViewGroup) view).setDescendantFocusability(
                    FOCUS_AFTER_DESCENDANTS);
        }
        return view;
    }

    public LocalActivityManager createLocalActyManager(Activity parent) {
        return mLocalActivityManager = new LocalActivityManager(parent, true);
    }

    @Override
    public AndroidInstance use(Object mp, Object... p) {
        return null;
    }
}
